
package com.airplane.hotdiscuss.ui;

import com.airplane.hotdiscuss.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.SlidingDrawer;
import android.widget.TextView;

public class SlidingDrawerDemo extends Activity {
    private SlidingDrawer mDrawer;

    private ImageButton imbg;

    private Boolean flag = false;

    private TextView tv;

    /*
     * (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.slidingdrawer);

        imbg = (ImageButton) findViewById(R.id.handle);
        mDrawer = (SlidingDrawer) findViewById(R.id.slidingdrawer);
        tv = (TextView) findViewById(R.id.tv);

        mDrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
            @Override
            public void onDrawerOpened() {
                flag = true;
                imbg.setImageResource(R.drawable.lyr_handle_expand_xml);
                hideView();
            }

        });

        mDrawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {
            @Override
            public void onDrawerClosed() {
                flag = false;
                imbg.setImageResource(R.drawable.lyr_handle_collapse_xml);
                showView();
            }

        });/*
        RelativeLayout rl = (RelativeLayout)findViewById(R.id.parent);
            for(int i=0;i<rl.getChildCount();i++){
                View v = rl.getChildAt(i);
                if(v != sd){
                    v.setVisibility(View.GONE);
                }
            }


        mDrawer.setOnDrawerScrollListener(new SlidingDrawer.OnDrawerScrollListener() {
            @Override
            public void onScrollEnded() {
                tv.setText("结束拖动");
            }

            @Override
            public void onScrollStarted() {
                tv.setText("开始拖动");
            }

        });*/

        mDrawer.setContentDescription("ContentDescription ");
    }

    public void hideView(){
        RelativeLayout rl = (RelativeLayout)findViewById(R.id.parent);
        for(int i=0;i<rl.getChildCount();i++){
            View v = rl.getChildAt(i);
            if(v != mDrawer){
                v.setVisibility(View.GONE);
            }
        }
    }

    public void showView(){
        RelativeLayout rl = (RelativeLayout)findViewById(R.id.parent);
        for(int i=0;i<rl.getChildCount();i++){
            View v = rl.getChildAt(i);
            v.setVisibility(View.VISIBLE);
        }
    }
}
